package com.tensquare.article.dao;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.tensquare.article.pojo.Article;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 数据访问接口
 *
 * @author Administrator
 */
public interface ArticleDao extends JpaRepository<Article, String>, JpaSpecificationExecutor<Article> {

    @Modifying
    @Query(value = "UPDATE tb_article SET state = 1 WHERE id = ?", nativeQuery = true)
    public void examine(String id);

    @Modifying
    @Query(value = "UPDATE tb_article SET thumbup = thumbup+1 WHERE id = ?", nativeQuery = true)
    public void updateThumbup(String id);

    @Query(value = "select * from tb_article where state='1' and ispublic='1' and channelid=? order by istop desc ", nativeQuery = true)
    public Page<Article> findByChannelid(String channelid, Pageable pageable);

    @Query(value = "select * from tb_article where state='1' and ispublic='1' order by istop desc ", nativeQuery = true)
    public Page<Article> findByChannelid( Pageable pageable);
}
